package com.qianfeng.ls.service.impl;

import com.qianfeng.ls.entity.UserEntity;
import com.qianfeng.ls.mapper.UserMapper;
import com.qianfeng.ls.pojo.UserPojo;
import com.qianfeng.ls.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public UserPojo login(UserEntity ue) {
        return userMapper.login(ue);
    }

    public boolean transfer(String uid1,String uid2,float money){

        //开启事务
        //给用户1扣钱
        boolean res1 = userMapper.updateUserMoney(uid1,-money);

        //打印回执等等,纪录一些信息等等动作   突然网络波动
//        int i = 1/0;

        //给用户2加钱
        boolean res2 = userMapper.updateUserMoney(uid2,money);

        //出现问题,回滚事务

        //提交事务
        return res1 && res2;
    }

}
